package com.thinkgem.jeesite.modules.sys.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.thinkgem.jeesite.modules.cloudfactory.entity.CloudfactoryUser;

public class LoginInterceptor implements HandlerInterceptor {

	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {
		CloudfactoryUser user = (CloudfactoryUser) request.getSession().getAttribute("cloudfactoryUser");

		if (user != null) {
			if (user.getId() != null && !"".equals(user.getId())) {

				return true;
			} else {
				response.sendRedirect(request.getContextPath() + "/a/loginCenter/goLogin");

				return false;
			}
		} else {
			response.sendRedirect(request.getContextPath() + "/a/loginCenter/goLogin");
			return false;
		}
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub

	}

}
